home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / DOUBLEDE / MAIN.C < prev    next >
C/C++ Source or Header  |  1988-07-28  |  4KB  |  197 lines

  1. #include "shell.h"
  2.  
  3. WindowPtr            windows[NUMWINDOWS];
  4. ControlHandle        demoButton[NUMWINDOWS];
  5. double                demo_double[NUMWINDOWS];
  6.  
  7. Rect                screen_rect;
  8.  
  9. MenuHandle            AppleMenu;
  10. MenuHandle            FileMenu;
  11. MenuHandle            EditMenu;
  12.  
  13. EventRecord            event;
  14.  
  15. int                    awaytime;
  16.  
  17. Boolean                chooserAlert;
  18. Boolean                quitting;
  19. Boolean                quit_on_wind_close;
  20.  
  21. WindowPtr            clip_window;
  22. int                    scrap_check;
  23. long                scrap_size;
  24. Handle                scrap_contents;
  25. long                scrap_type;
  26.  
  27. ProcPtr                mainloop;
  28.  
  29. int                    errno;
  30. int                    w_index;
  31.  
  32. /*====================================================================
  33.  
  34.     multimainloop()
  35.     
  36.     an event loop to execute when running under MultiFinder
  37.     
  38. ====================================================================*/    
  39. int multimainloop()
  40. {
  41.     if (WaitNextEvent(everyEvent,&event,awaytime,NIL))
  42.         handleanevent();
  43.     fixmenus();
  44. }
  45.  
  46. /*====================================================================
  47.  
  48.     unimainloop()
  49.     
  50.     an event loop to execute when _not_ running under MultiFinder
  51.     
  52. ====================================================================*/    
  53. int unimainloop()
  54. {
  55.     SystemTask();
  56.     if (GetNextEvent(everyEvent,&event))
  57.         handleanevent();
  58.     fixmenus();
  59. }
  60.  
  61. /*====================================================================
  62.  
  63.     multiopening()
  64.     
  65.     called when being launched under MultiFinder, loops until no
  66.     events are in the queue, allows application to launch as
  67.     frontmost
  68.     
  69. ====================================================================*/    
  70. multiopening()
  71. {
  72.     Boolean            multi_opening;
  73.     
  74.     do{
  75.         if (multi_opening = WaitNextEvent(everyEvent,&event,awaytime,NIL))
  76.             handleanevent();
  77.     }while(multi_opening);
  78. }
  79.  
  80. /*====================================================================
  81.  
  82.     main()
  83.     
  84.     the main program.  Calls routines to initialize Mac Managers, makes
  85.     menus & windows, contains the call to the event loop.
  86.     
  87. ====================================================================*/    
  88. main()
  89. {
  90.  
  91.     init();
  92.  
  93.     if (WNEavail()){
  94.         mainloop = multimainloop;    /* MultiFinder event loop    */
  95.         multiopening();
  96.     }
  97.     else
  98.         
  99.         mainloop = unimainloop;        /*    Finder event loop        */
  100.  
  101.     makemenus();
  102.     makewindows();
  103.  
  104.     chooserAlert = SetChooserAlert(FALSE);    /*  bypass page setup warning
  105.                                                 when choosing a printer        */
  106.  
  107.     getourscrap();
  108.     quitting = FALSE;
  109.  
  110.  
  111.     /*
  112.         Execute event loop until user quits
  113.     */
  114.  
  115.     while(!quitting)
  116.         (*mainloop)();                
  117.  
  118.  
  119.     /*    
  120.         set cursor to watch during application closing
  121.     */
  122.     
  123.     SetCursor(*(CursHandle)GetCursor(watchCursor));
  124.     
  125.     /*
  126.         close application windows, and restore the Chooser
  127.         page setup warning
  128.     */
  129.     close_app_windows();
  130.     SetChooserAlert(chooserAlert);
  131. }
  132.  
  133. /*====================================================================
  134.  
  135.     close_app_windows()
  136.     
  137.     closes application windows and Desk Accessories that are open when
  138.     the user quits the application
  139.     
  140. ====================================================================*/    
  141. close_app_windows()
  142. {
  143.     WindowPeek        wRec;
  144.  
  145.     while ( FrontWindow() != NIL){
  146.         wRec = (WindowPeek)FrontWindow();
  147.         if ((wRec->windowKind==dialogKind) || (wRec->windowKind==userKind))
  148.             HideWindow(FrontWindow());
  149.         else
  150.             CloseDeskAcc(wRec->windowKind);
  151.     }
  152. }
  153.  
  154. /*====================================================================
  155.  
  156.     easy_out()
  157.     
  158.     An attempt to exit_to_shell (usually the Finder) when a system
  159.     error occurs.
  160.     
  161. ====================================================================*/    
  162. easy_out()
  163. {
  164.     ExitToShell();
  165. }
  166.  
  167. /*====================================================================
  168.  
  169.     init()
  170.     
  171.     Initialize Macintosh Managers, create master pointers,
  172.     initialize random number generator, initialize the global
  173.     boolean quit_on_wind_close
  174.     
  175. ====================================================================*/    
  176. init()
  177. {
  178.     int                index;
  179.  
  180.     MaxApplZone();
  181.     for (index=1;index<11;index++)
  182.         MoreMasters();
  183.     InitGraf(&thePort);
  184.     InitFonts();
  185.     FlushEvents(everyEvent,0);
  186.     InitWindows();
  187.     InitMenus();
  188.     TEInit();
  189.     InitDialogs(easy_out);
  190.     InitCursor();
  191.     randSeed = TickCount();
  192.     
  193.     quit_on_wind_close = TRUE;
  194.     awaytime = 60;
  195.     screen_rect = screenBits.bounds;
  196. }
  197.